<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>预约确认 - 驾校约车系统</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        /* 导航栏样式开始 */
        header {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1000;
            background-color: white;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }

        .header-container {
            max-width: 900px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 20px;
        }

        .logo {
            display: flex;
            align-items: center;
        }

        .logo-icon {
            width: 40px;
            height: 40px;
            background-color: #409EFF;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            margin-right: 10px;
        }

        .logo-text {
            font-size: 24px;
            font-weight: bold;
            color: #2c3e50;
        }

        .nav-links {
            display: flex;
            list-style: none;
            margin: 0;
            padding: 0;
        }

        .nav-links li {
            margin-left: 20px;
        }

        .nav-links a {
            text-decoration: none;
            color: #34495e;
            font-size: 16px;
            font-weight: 500;
            transition: color 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .nav-links a::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 0;
            height: 0.5px;
            background: #409EFF;
            transition: all 0.3s ease;
        }

        .nav-links a:hover {
            color: #409EFF;
        }

        .nav-links a:hover::after {
            width: 100%;
        }
        /* 导航栏样式结束 */

        /* 确认页面样式 */
        .confirm-container {
            max-width: 1200px;
            margin: 100px auto 40px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .confirm-header {
            background-color: #f0f8ff;
            padding: 20px 30px;
            border-bottom: 1px solid #e6f3ff;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .booking-table {
            width: 100%;
            border-collapse: collapse;
        }

        .booking-table th,
        .booking-table td {
            padding: 15px;
            text-align: left;
            border-bottom: 1px solid #e6f3ff;
        }

        .booking-table th {
            background-color: #f8faff;
            color: #666;
            font-weight: 500;
        }

        .booking-table tr:hover {
            background-color: #f8faff;
        }

        .status-badge {
            padding: 4px 12px;
            border-radius: 12px;
            font-size: 14px;
            font-weight: 500;
        }

        .status-pending {
            background-color: #fff7e6;
            color: #ffab00;
        }

        .status-confirmed {
            background-color: #e6f7ee;
            color: #52c41a;
        }

        .status-rejected {
            background-color: #fff1f0;
            color: #f5222d;
        }

        .action-btn {
            padding: 6px 12px;
            border-radius: 4px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            border: none;
            margin-right: 5px;
        }

        .btn-confirm {
            background-color: #52c41a;
            color: white;
        }

        .btn-confirm:hover {
            background-color: #49ad17;
        }

        .btn-reject {
            background-color: #ff4d4f;
            color: white;
        }

        .btn-reject:hover {
            background-color: #f5222d;
        }

        .btn-view {
            background-color: #409EFF;
            color: white;
        }

        .btn-view:hover {
            background-color: #2288ee;
        }

        /* 模态框样式 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 1000;
        }

        .modal-content {
            position: relative;
            background-color: white;
            margin: 100px auto;
            padding: 20px;
            width: 500px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        }

        .modal-header {
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #e6f3ff;
        }

        .close {
            position: absolute;
            right: 20px;
            top: 20px;
            font-size: 24px;
            cursor: pointer;
            color: #999;
        }

        .close:hover {
            color: #666;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-label {
            display: block;
            margin-bottom: 8px;
            color: #666;
            font-weight: 500;
        }

        .form-input {
            width: 100%;
            padding: 8px 12px;
            border: 1px solid #d9d9d9;
            border-radius: 4px;
            font-size: 14px;
        }

        .form-input:focus {
            outline: none;
            border-color: #409EFF;
            box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
        }

        .modal-footer {
            margin-top: 20px;
            text-align: right;
        }
    </style>
</head>
<body style="background-color: #e6f3ff; margin: 0; padding: 20px; font-family: Arial, sans-serif;">
    <!-- 导航栏 -->
    <header>
        <div class="header-container" style="width: 1000px;">
            <div class="logo">
                <div class="logo-icon">
                    <i class="fa fa-car text-white text-xl"></i>
                </div>
                <span class="logo-text">驾校学员交流区</span>
            </div>
            <nav>
                <ul class="nav-links">
                    <a href="/zrz/daohanglanLayui" class="text-dark hover:text-primary nav-link-hover font-medium">首页</a>&nbsp;&nbsp;&nbsp;
                    <a href="#courses" class="text-dark hover:text-primary nav-link-hover font-medium">课程</a>&nbsp;&nbsp;&nbsp;
                    <a href="/ljk/coach/index" class="text-dark hover:text-primary nav-link-hover font-medium">教练团队</a>&nbsp;&nbsp;&nbsp;
                    <a href="/hzj/jiaxiaoguanliList" class="text-dark hover:text-primary nav-link-hover font-medium">基本信息</a>&nbsp;&nbsp;&nbsp;
                    <a href="/kaiban/page" class="text-dark hover:text-primary nav-link-hover font-medium">开班信息</a>&nbsp;&nbsp;&nbsp;
                    <a href="/zjy/liuyan" class="text-dark hover:text-primary nav-link-hover font-medium">用户留言</a>&nbsp;&nbsp;&nbsp;
                    <a href="/zjy/zixun" class="text-dark hover:text-primary nav-link-hover font-medium">用户咨询</a>&nbsp;&nbsp;&nbsp;
                    <a href="/zjh/yueche_confirm" class="text-dark hover:text-primary nav-link-hover font-medium">预约确认</a>
                </ul>
            </nav>
            <a href="#" class="contact-button hidden md:block">联系客服</a>
        </div>
    </header>

    <!-- 确认内容 -->
    <div class="confirm-container">
        <div class="confirm-header">
            <h2 style="color: #409EFF; margin: 0;">预约确认管理</h2>
            <div>
                <button onclick="filterBookings('all')" class="action-btn btn-view">全部</button>
                <button onclick="filterBookings('待确认')" class="action-btn" style="background-color: #ffab00; color: white;">待确认</button>
                <button onclick="filterBookings('已确认')" class="action-btn btn-confirm">已确认</button>
                <button onclick="filterBookings('已拒绝')" class="action-btn btn-reject">已拒绝</button>
            </div>
        </div>

        <div style="overflow-x: auto;">
            <table class="booking-table">
                <thead>
                    <tr>
                        <th>预约编号</th>
                        <th>学员姓名</th>
                        <th>联系电话</th>
                        <th>驾照类型</th>
                        <th>预约日期</th>
                        <th>时间段</th>
                        <th>教练</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="bookingTableBody">
                    <!-- 预约数据将通过JavaScript动态添加 -->
                </tbody>
            </table>
        </div>
    </div>

    <!-- 确认模态框 -->
    <div id="confirmModal" class="modal">
        <div class="modal-content">
            <div class="modal-header">
                <h3 style="margin: 0; color: #409EFF;">确认预约</h3>
                <span class="close" onclick="closeModal('confirmModal')">&times;</span>
            </div>
            <div class="form-group">
                <label class="form-label">预约编号</label>
                <div id="confirmBookingId" style="color: #666;"></div>
            </div>
            <div class="form-group">
                <label class="form-label">备注信息</label>
                <textarea id="confirmNote" class="form-input" rows="3" placeholder="添加备注信息（可选）"></textarea>
            </div>
            <div class="modal-footer">
                <button onclick="closeModal('confirmModal')" class="action-btn" style="background-color: #f0f0f0; color: #666;">取消</button>
                <button onclick="submitConfirm()" class="action-btn btn-confirm">确认预约</button>
            </div>
        </div>
    </div>

    <!-- 拒绝模态框 -->
    <div id="rejectModal" class="modal">
        <div class="modal-content">
            <div class="modal-header">
                <h3 style="margin: 0; color: #ff4d4f;">拒绝预约</h3>
                <span class="close" onclick="closeModal('rejectModal')">&times;</span>
            </div>
            <div class="form-group">
                <label class="form-label">预约编号</label>
                <div id="rejectBookingId" style="color: #666;"></div>
            </div>
            <div class="form-group">
                <label class="form-label">拒绝原因</label>
                <textarea id="rejectReason" class="form-input" rows="3" placeholder="请输入拒绝原因"></textarea>
            </div>
            <div class="modal-footer">
                <button onclick="closeModal('rejectModal')" class="action-btn" style="background-color: #f0f0f0; color: #666;">取消</button>
                <button onclick="submitReject()" class="action-btn btn-reject">确认拒绝</button>
            </div>
        </div>
    </div>

    <script>
        // 模拟预约数据
        let bookings = [
            {
                id: 'YC20240120001',
                name: '张三',
                phone: '13800138000',
                license: 'C1',
                date: '2024-01-20',
                time: '上午 8:00-10:00',
                instructor: '李教练',
                status: 'pending'
            },

        ];

        // 当前选中的预约ID
        let currentBookingId = '';

        // 渲染预约列表
        function renderBookings(filterStatus = 'all') {
            const tbody = document.getElementById('bookingTableBody');
            tbody.innerHTML = '';

            const filteredBookings = filterStatus === 'all'
                ? bookings
                : bookings.filter(booking => booking.status === filterStatus);

            filteredBookings.forEach(booking => {
                const tr = document.createElement('tr');
                tr.innerHTML = `
                    <td>${booking.id}</td>
                    <td>${booking.name}</td>
                    <td>${booking.phone}</td>
                    <td>${booking.license}</td>
                    <td>${booking.date}</td>
                    <td>${booking.time}</td>
                    <td>${booking.instructor}</td>
                    <td>
                        <span class="status-badge status-${booking.status}">
                            ${getStatusText(booking.status)}
                        </span>
                    </td>
                    <td>
                        ${booking.status === '待确认' ? `
                            <button onclick="showConfirmModal('${booking.id}')" class="action-btn btn-confirm">确认</button>
                            <button onclick="showRejectModal('${booking.id}')" class="action-btn btn-reject">拒绝</button>
                        ` : `
                            <button onclick="viewBooking('${booking.id}')" class="action-btn btn-view">查看</button>
                        `}
                    </td>
                `;
                tbody.appendChild(tr);
            });
        }

        // 获取状态文本
        function getStatusText(status) {
            switch(status) {
                case 'pending': return '待确认';
                case 'confirmed': return '已确认';
                case 'rejected': return '已拒绝';
                default: return status;
            }
        }

        // 显示确认模态框
        function showConfirmModal(bookingId) {
            currentBookingId = bookingId;
            document.getElementById('confirmBookingId').textContent = bookingId;
            document.getElementById('confirmModal').style.display = 'block';
        }

        // 显示拒绝模态框
        function showRejectModal(bookingId) {
            currentBookingId = bookingId;
            document.getElementById('rejectBookingId').textContent = bookingId;
            document.getElementById('rejectModal').style.display = 'block';


        }

        // 关闭模态框
        function closeModal(modalId) {
            document.getElementById(modalId).style.display = 'none';
            currentBookingId = '';
        }

        // 提交确认
        function submitConfirm() {
            const note = document.getElementById('confirmNote').value;
            const booking = bookings.find(b => b.id === currentBookingId);
            if (booking) {
                fetch('/zjh/confirmed', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({id: booking.id, note: note.trim() || '无备注信息'})
                }).then(data => {
                    booking.status = '已确认';
                    alert('预约已确认！');
                    closeModal('confirmModal');
                    renderBookings();
                });

            }
        }

        // 提交拒绝
        function submitReject() {
            const reason = document.getElementById('rejectReason').value;
            if (!reason.trim()) {
                alert('请输入拒绝原因');
                return;
            }
            const booking = bookings.find(b => b.id === currentBookingId);


            fetch('/zjh/rejected', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({id: booking.id, reason: reason})
            }).then(data => {
                booking.status = '已拒绝';
                alert('预约已拒绝！');
                closeModal('rejectModal');
                renderBookings();
            });

        }

        // 查看预约详情
        function viewBooking(bookingId) {
            const booking = bookings.find(b => b.id === bookingId);
            if (booking) {
                alert(`预约详情：\n预约编号：${booking.id}\n学员姓名：${booking.name}\n联系电话：${booking.phone}\n驾照类型：${booking.license}\n预约日期：${booking.date}\n时间段：${booking.time}\n教练：${booking.instructor}\n状态：${getStatusText(booking.status)}`);
            }
        }

        // 筛选预约
        function filterBookings(status) {
            renderBookings(status);
        }

        // 导航栏滚动效果
        window.addEventListener('scroll', function() {
            const header = document.querySelector('header');
            if (window.scrollY > 50) {
                header.classList.add('shadow-md');
                header.style.padding = '10px 0';
            } else {
                header.classList.remove('shadow-md');
                header.style.padding = '15px 0';
            }
        });

        function fetchData(){

            return new Promise((resolve, reject) => {
                fetch('/zjh/getAll', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({})
                })
                    .then(response => response.json())
                    .then(data => {
                        bookings = []; // 清空现有预约数据
                        data.data.forEach(item => {
                            const name = item.studentName;
                            const phone = item.phone;
                            const license = item.licenseType;
                            const date = item.reservationDate.substring(0, 10);
                            const time = item.timeSlot;
                            const instructor = item.coachName;
                            const id = item.id;
                            const status = item.status;
                            // 添加新预约到记录列表
                            bookings.push({id, name, phone, license, date, time, instructor, status});
                        });
                        resolve(bookings);
                    })
                    .catch(error => {
                        console.error('获取预约数据失败:', error);
                        reject(error);
                    });
            });



        }

        // 初始化页面
        window.onload = function() {
            fetchData().then(() => {
                renderBookings();
            }).catch(error => {
                console.error('初始化数据失败:', error);
            });
            // renderBookings();
        };
    </script>
</body>
</html>
